package com.xywl.escort.adapter;

import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xywl.escort.R;
import com.xywl.escort.bean.RepoOrderResp;
import com.xywl.escort.widget.CircleProgress;
import com.xywl.escort.widget.GlideApp;

import java.util.List;

import timber.log.Timber;

public class RepoOrderAdapter extends BaseQuickAdapter<RepoOrderResp.DataBean.ListBean, BaseViewHolder> {
    public RepoOrderAdapter(int layoutResId, @Nullable List<RepoOrderResp.DataBean.ListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, RepoOrderResp.DataBean.ListBean item) {
        ImageView imageView = helper.getView(R.id.img_project);
        GlideApp.with(mContext)
                .load(item.coverUrl)
                .centerCrop()
                .placeholder(R.mipmap.icon_default_picture)
                .into(imageView);

        helper.setText(R.id.text_title, item.projectName);
        helper.setText(R.id.text_time, item.createTime);

        String textCount = "收购份数 " + item.num + "份";
        SpannableString spanString = new SpannableString(textCount);
        //再构造一个改变字体颜色的Span
        ForegroundColorSpan span = new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.aid_prompt_color));
        //将这个Span应用于指定范围的字体
        spanString.setSpan(span, textCount.indexOf("数") + 1, textCount.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        AbsoluteSizeSpan span1 = new AbsoluteSizeSpan(15, true);
        spanString.setSpan(span1, textCount.indexOf("数") + 1, textCount.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        helper.setText(R.id.text_count, spanString);
        LinearLayout layoutTools = helper.getView(R.id.layout_tools);
        switch (item.auditStatus) {
            case 1:
                helper.setText(R.id.text_first_line, "申请");
                helper.setText(R.id.text_second_line, "收购中");
                layoutTools.setVisibility(View.GONE);
                break;
            case 2:
                helper.setText(R.id.text_first_line, "收购");
                helper.setText(R.id.text_second_line, "成功");
                layoutTools.setVisibility(View.VISIBLE);
                break;
            case 3:
                helper.setText(R.id.text_first_line, "审核");
                helper.setText(R.id.text_second_line, "不通过");
                layoutTools.setVisibility(View.VISIBLE);
                break;
            default:
                helper.setText(R.id.text_first_line, "审核");
                helper.setText(R.id.text_second_line, "不通过");
                layoutTools.setVisibility(View.VISIBLE);
                break;
        }
        CircleProgress circleProgress = helper.getView(R.id.circleProgress);
        circleProgress.setMax(100);
        circleProgress.setProgress(100);

        helper.addOnClickListener(R.id.btn_delete_order);
        helper.addOnClickListener(R.id.image_more);
    }
}
